package rj19.xqq.app1128;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import java.util.List;

public class NumAdapter extends RecyclerView.Adapter<NumAdapter.VH> {
    private View view;
    private List<Strings> list;
    private Context context;
    private MyItemOnclick myItemOnclick;

    public NumAdapter(List<Strings> list, Context context) {
        this.list = list;
        this.context = context;
    }

    public void MyItemOnclick(MyItemOnclick myItemOnclick){
        this.myItemOnclick = myItemOnclick;
    }

    @NonNull
    @Override
    public NumAdapter.VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.item,parent,false);
        VH vh = new VH(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(@NonNull NumAdapter.VH holder, final int position) {

        holder.num.setText(list.get(position).getNum());


        final String newsid = String.valueOf(list.get(position).getNum());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (myItemOnclick != null){
                    int item = getItemViewType(position);
                    if (item != RecyclerView.NO_POSITION){
                        myItemOnclick.onItemClick(view,position,newsid);
                    }


                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class VH extends RecyclerView.ViewHolder {

        TextView num;
        public VH(@NonNull View itemView) {
            super(itemView);
            num = itemView.findViewById(R.id.txt);

        }
    }
}
